import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    Color myColor = Color(0xFF42A5F5); // 格式0xAARRGGBB

    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // TRY THIS: Try changing the color here to a specific color (to
        // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
        // change color while the other colors stay the same.
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: SizedBox.expand(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text('早起的年轻人', style: TextStyle(fontSize: 22, color: Colors.red)),
              Text(
                '早起的年轻人',
                style: TextStyle(fontSize: 22, color: Colors.red[900]),
              ),
              Text(
                '早起的年轻人',
                style: TextStyle(fontSize: 22, color: Color(0xE6A04956)),
              ),

              Text(
                '早起的年轻人',
                style: TextStyle(
                  fontSize: 22,
                  color: Color.fromARGB(255, 100, 100, 100),
                ),
              ),

              Text(
                '早起的年轻人',
                style: TextStyle(
                  fontSize: 22,
                  color: Color.fromRGBO(100, 100, 100, 0.5),
                ),
              ),
              Text(
                '早起的年轻人',
                style: TextStyle(fontSize: 22, color: hexToColor('#42a5a5')),
              ),
            ],
          ),
        ),
      ),
      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  Color? hexToColor(String s, {double alpha = 1.0}) {
    String hexCode = s.replaceAll('#', '');
    if (hexCode.length == 6) {
      hexCode = 'FF$hexCode';
    }
    return Color(int.parse(hexCode, radix: 16)).withValues(alpha: alpha);
  }
}
